/////////////////////////////////////////////////////////////////////////////
// Name:        Propulsion_Diag.cpp
// Purpose:     Dialog for Propulsion
// Author:      Matthew Gong
// Created:     07/25/2005
// Copyright:   (c) Matthew Gong
// Licence:     GPL licence
/////////////////////////////////////////////////////////////////////////////

#ifdef __GNUG__
// #pragma implementation
#endif

// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

// -*- C++ -*- generated by wxGlade 0.3.5.1 on Tue May 24 15:50:46 2005

#include <wx/valgen.h>
#include "Propulsion_Diag.h"
#include "MyApp.h"

ClientData_engine::ClientData_engine(const wxString & e, const wxString & t)
{
  file_e = e;
  file_t = t;
  loc_e = loc_t = MyColumn3(wxT("M"));
  ori_e = ori_t = MyColumn3(wxT("DEG"));
  feed_list.clear();
}

void ClientData_engine::Load(JSBSim::Element * el)
{
  file_e = std2wxstr(el->GetAttributeValue("file"));
  JSBSim::Element * tmp;
  if (tmp = el->FindElement("location"))
  {
    loc_e.unit = std2wxstr(tmp->GetAttributeValue("unit"));
    loc_e.x1    = tmp->FindElementValueAsNumber("x");
    loc_e.x2    = tmp->FindElementValueAsNumber("y");
    loc_e.x3    = tmp->FindElementValueAsNumber("z");
  }
  if (tmp = el->FindElement("orient"))
  {
    ori_e.unit = std2wxstr(tmp->GetAttributeValue("unit"));
    ori_e.x1    = tmp->FindElementValueAsNumber("roll");
    ori_e.x2    = tmp->FindElementValueAsNumber("pitch");
    ori_e.x3    = tmp->FindElementValueAsNumber("yaw");
  }
  tmp = el->FindElement("feed");
  while (tmp)
  {
    unsigned i = (unsigned)tmp->GetDataAsNumber();
    feed_list.push_back(i);
    tmp = el->FindNextElement("feed");
  }
  
  JSBSim::Element * thr;
  if (thr = el->FindElement("thruster"))
  {
    file_t = std2wxstr(thr->GetAttributeValue("file"));
    if (tmp = thr->FindElement("location"))
    {
    loc_t.unit = std2wxstr(tmp->GetAttributeValue("unit"));
    loc_t.x1    = tmp->FindElementValueAsNumber("x");
    loc_t.x2    = tmp->FindElementValueAsNumber("y");
    loc_t.x3    = tmp->FindElementValueAsNumber("z");
    }
    if (tmp = thr->FindElement("orient"))
    {
    ori_t.unit = std2wxstr(tmp->GetAttributeValue("unit"));
    ori_t.x1    = tmp->FindElementValueAsNumber("roll");
    ori_t.x2    = tmp->FindElementValueAsNumber("pitch");
    ori_t.x3    = tmp->FindElementValueAsNumber("yaw");
    }
  }
}

void ClientData_engine::Save(wxTextOutputStream & out, const wxString & prefix)
{
  out << prefix << wxT("<engine file=\"") << file_e << wxT("\">\n");

  wxString pre = prefix + wxT("    ");
  out << pre << wxT("<location unit=\"") << loc_e.unit << wxT("\">\n");
  out << pre << wxT("    <x> ") << wxString::Format(wxT("%g"), loc_e.x1) << wxT(" </x>\n");
  out << pre << wxT("    <y> ") << wxString::Format(wxT("%g"), loc_e.x2) << wxT(" </y>\n");
  out << pre << wxT("    <z> ") << wxString::Format(wxT("%g"), loc_e.x3) << wxT(" </z>\n");
  out << pre << wxT("</location>\n");
  out << pre << wxT("<orient unit=\"") << ori_e.unit << wxT("\">\n");
  out << pre << wxT("    <roll> ") << wxString::Format(wxT("%g"), ori_e.x1) << wxT(" </roll>\n");
  out << pre << wxT("    <pitch> ") << wxString::Format(wxT("%g"), ori_e.x2) << wxT(" </pitch>\n");
  out << pre << wxT("    <yaw> ") << wxString::Format(wxT("%g"), ori_e.x3) << wxT(" </yaw>\n");
  out << pre << wxT("</orient>\n");

  for (size_t i=0; i< feed_list.size(); ++i)
  {
    out << pre << wxT("<feed>") << feed_list[i] << wxT("</feed>\n");
  }

  out << pre << wxT("<thruster file=\"") << file_t << wxT("\">\n");
  
  wxString pre2 = pre + wxT("    ");
  out << pre2 << wxT("<location unit=\"") << loc_t.unit << wxT("\">\n");
  out << pre2 << wxT("    <x> ") << wxString::Format(wxT("%g"), loc_t.x1) << wxT(" </x>\n");
  out << pre2 << wxT("    <y> ") << wxString::Format(wxT("%g"), loc_t.x2) << wxT(" </y>\n");
  out << pre2 << wxT("    <z> ") << wxString::Format(wxT("%g"), loc_t.x3) << wxT(" </z>\n");
  out << pre2 << wxT("</location>\n");
  out << pre2 << wxT("<orient unit=\"") << ori_t.unit << wxT("\">\n");
  out << pre2 << wxT("    <roll> ") << wxString::Format(wxT("%g"), ori_t.x1) << wxT(" </roll>\n");
  out << pre2 << wxT("    <pitch> ") << wxString::Format(wxT("%g"), ori_t.x2) << wxT(" </pitch>\n");
  out << pre2 << wxT("    <yaw> ") << wxString::Format(wxT("%g"), ori_t.x3) << wxT(" </yaw>\n");
  out << pre2 << wxT("</orient>\n");
  
  out << pre << wxT("</thruster>\n");

  
  out << prefix << wxT("</engine>\n");

}


ClientData_tank::ClientData_tank()
{
  type = wxT("FUEL");
  capacity = contents = 0;
  capacity_unit = contents_unit = wxT("KG");
  loc = MyColumn3(wxT("M"));
}

void ClientData_tank::Load(JSBSim::Element * el)
{
  type = std2wxstr(el->GetAttributeValue("type"));
  JSBSim::Element * tmp;
  if (tmp = el->FindElement("capacity"))
  {
    capacity_unit = std2wxstr(tmp->GetAttributeValue("unit"));
    capacity = tmp->GetDataAsNumber();
  }
  if (tmp = el->FindElement("contents"))
  {
    contents_unit = std2wxstr(tmp->GetAttributeValue("unit"));
    contents = tmp->GetDataAsNumber();
  }
  if (tmp = el->FindElement("location"))
  {
    loc.unit = std2wxstr(tmp->GetAttributeValue("unit"));
    loc.x1    = tmp->FindElementValueAsNumber("x");
    loc.x2    = tmp->FindElementValueAsNumber("y");
    loc.x3    = tmp->FindElementValueAsNumber("z");
  }
}

void ClientData_tank::Save(wxTextOutputStream & out, const wxString & prefix)
{
  out << prefix << wxT("<tank type=\"") << type << wxT("\">\n");
  wxString pre = prefix + wxT("    ");
  out << pre << wxT("<location unit=\"") << loc.unit << wxT("\">\n");
  out << pre << wxT("    <x> ") << wxString::Format(wxT("%g"), loc.x1) << wxT(" </x>\n");
  out << pre << wxT("    <y> ") << wxString::Format(wxT("%g"), loc.x2) << wxT(" </y>\n");
  out << pre << wxT("    <z> ") << wxString::Format(wxT("%g"), loc.x3) << wxT(" </z>\n");
  out << pre << wxT("</location>\n");
  out << pre << wxT("<capacity unit=\"") << capacity_unit << wxT("\">") << wxString::Format(wxT("%g"), capacity) << wxT("</capacity>\n");
  out << pre << wxT("<contents unit=\"") << contents_unit << wxT("\">") << wxString::Format(wxT("%g"), contents) << wxT("</contents>\n");

  out << prefix << wxT("</tank>\n");
}

wxString ClientData_tank::GetText()
{
  return type + wxString::Format(wxT(" weighs %g  %s at [%g, %g, %g] in %s"), contents, contents_unit.c_str(), loc.x1, loc.x2, loc.x3, loc.unit.c_str());  
}


MyColumn4Str & MyColumn4Str::operator = (const MyColumn3 & s)
{
  x1 = wxString::Format(wxT("%g"), s.x1);
  x2 = wxString::Format(wxT("%g"), s.x2);
  x3 = wxString::Format(wxT("%g"), s.x3);
  unit = s.unit;
  return *this;
}

MyColumn3 & MyColumn3::operator = (const MyColumn4Str & s)
{
  double tmp;
  s.x1.ToDouble(&tmp);
  x1 = tmp;
  s.x2.ToDouble(&tmp);
  x2 = tmp;
  s.x3.ToDouble(&tmp);
  x3 = tmp;
  unit = s.unit;
  return *this;
}


EngineThrusterDialog::EngineThrusterDialog(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
    wxDialog(parent, id, title, pos, size, style)
{
    // begin wxGlade: EngineThrusterDialog::EngineThrusterDialog
    sizer_4_copy_staticbox = new wxStaticBox(this, -1, _("Orient"));
    sizer_2_staticbox = new wxStaticBox(this, -1, _("Engine"));
    sizer_5_staticbox = new wxStaticBox(this, -1, _("Feed"));
    sizer_4_copy_1_staticbox = new wxStaticBox(this, -1, _("Location"));
    sizer_4_copy_copy_staticbox = new wxStaticBox(this, -1, _("Orient"));
    sizer_2_copy_staticbox = new wxStaticBox(this, -1, _("Thruster"));
    sizer_4_staticbox = new wxStaticBox(this, -1, _("Location"));
    label_name = new wxStaticText(this, -1, _("Engine Name:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_name = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_ASCII, &file_e) );
    label_x = new wxStaticText(this, -1, _("x ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_x = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(loc_e.x1)) );
    label_y = new wxStaticText(this, -1, _("y ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_y = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(loc_e.x2)) );
    label_z = new wxStaticText(this, -1, _("z ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_z = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(loc_e.x3)) );
    const wxString combo_box_pos_unit_choices[] = {
        wxT("IN"),
        wxT("FT"),
        wxT("M")
    };
    combo_box_pos_unit = new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 3, combo_box_pos_unit_choices, wxCB_DROPDOWN|wxCB_READONLY, wxGenericValidator( &(loc_e.unit)) );
    label_roll = new wxStaticText(this, -1, _("roll ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_roll = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(ori_e.x1)) );
    label_pitch = new wxStaticText(this, -1, _("pitch ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_pitch = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(ori_e.x2)) );
    label_yaw = new wxStaticText(this, -1, _("yaw ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_yaw = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(ori_e.x3)) );
    const wxString combo_box_orient_unit_choices[] = {
        wxT("DEG"),
        wxT("RAD")
    };
    combo_box_orient_unit = new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_orient_unit_choices, wxCB_DROPDOWN|wxCB_READONLY, wxGenericValidator( &(ori_e.unit)) );
    text_ctrl_feed = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NONE, &feed) );
    label_name_copy = new wxStaticText(this, -1, _("Thruster Name:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_name_copy = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_ASCII, &file_t) );
    label_x_copy_1 = new wxStaticText(this, -1, _("x ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_x_copy_1 = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(loc_t.x1)) );
    label_y_copy_1 = new wxStaticText(this, -1, _("y ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_y_copy_1 = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(loc_t.x2)) );
    label_z_copy_1 = new wxStaticText(this, -1, _("z ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_z_copy_1 = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(loc_t.x3)) );
    const wxString combo_box_pos_unit_copy_1_choices[] = {
        wxT("IN"),
        wxT("FT"),
        wxT("M")
    };
    combo_box_pos_unit_copy_1 = new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 3, combo_box_pos_unit_copy_1_choices, wxCB_DROPDOWN|wxCB_READONLY, wxGenericValidator(&(loc_t.unit)) );
    label_roll_copy = new wxStaticText(this, -1, _("roll ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_roll_copy = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(ori_t.x1)) );
    label_pitch_copy = new wxStaticText(this, -1, _("pitch ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_pitch_copy = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(ori_t.x2)) );
    label_yaw_copy = new wxStaticText(this, -1, _("yaw ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_yaw_copy = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(ori_t.x3)) );
    const wxString combo_box_orient_unit_copy_choices[] = {
        wxT("DEG"),
        wxT("RAD")
    };
    combo_box_orient_unit_copy = new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_orient_unit_copy_choices, wxCB_DROPDOWN|wxCB_READONLY, wxGenericValidator(&(ori_t.unit)) );
    button_ok = new wxButton(this, wxID_OK, _("OK"));
    button_cancel = new wxButton(this, wxID_CANCEL, _("Cancel"));

    set_properties();
    do_layout();
    // end wxGlade
}


void EngineThrusterDialog::set_properties()
{
    // begin wxGlade: EngineThrusterDialog::set_properties
    label_name->SetMinSize(wxSize(120, 20));
    //label_x->SetMinSize(wxSize(45, 20));
    //label_y->SetMinSize(wxSize(40, 20));
    //label_z->SetMinSize(wxSize(40, 20));
    combo_box_pos_unit->SetSelection(0);
    //label_roll->SetMinSize(wxSize(45, 20));
    //label_pitch->SetMinSize(wxSize(40, 20));
    //label_yaw->SetMinSize(wxSize(40, 20));
    combo_box_orient_unit->SetSelection(0);
    label_name_copy->SetMinSize(wxSize(120, 20));
    //label_x_copy_1->SetMinSize(wxSize(45, 20));
    //label_y_copy_1->SetMinSize(wxSize(40, 20));
    //label_z_copy_1->SetMinSize(wxSize(40, 20));
    combo_box_pos_unit_copy_1->SetSelection(0);
    //label_roll_copy->SetMinSize(wxSize(45, 20));
    //label_pitch_copy->SetMinSize(wxSize(40, 20));
    //label_yaw_copy->SetMinSize(wxSize(40, 20));
    combo_box_orient_unit_copy->SetSelection(0);
    button_cancel->SetFocus();
    // end wxGlade
}


void EngineThrusterDialog::do_layout()
{
    // begin wxGlade: EngineThrusterDialog::do_layout
    wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_6 = new wxBoxSizer(wxHORIZONTAL);
    wxStaticBoxSizer* sizer_2_copy = new wxStaticBoxSizer(sizer_2_copy_staticbox, wxVERTICAL);
    wxStaticBoxSizer* sizer_4_copy_copy = new wxStaticBoxSizer(sizer_4_copy_copy_staticbox, wxHORIZONTAL);
    wxStaticBoxSizer* sizer_4_copy_1 = new wxStaticBoxSizer(sizer_4_copy_1_staticbox, wxHORIZONTAL);
    wxBoxSizer* sizer_3_copy = new wxBoxSizer(wxHORIZONTAL);
    wxStaticBoxSizer* sizer_5 = new wxStaticBoxSizer(sizer_5_staticbox, wxHORIZONTAL);
    wxStaticBoxSizer* sizer_2 = new wxStaticBoxSizer(sizer_2_staticbox, wxVERTICAL);
    wxStaticBoxSizer* sizer_4_copy = new wxStaticBoxSizer(sizer_4_copy_staticbox, wxHORIZONTAL);
    wxStaticBoxSizer* sizer_4 = new wxStaticBoxSizer(sizer_4_staticbox, wxHORIZONTAL);
    wxBoxSizer* sizer_3 = new wxBoxSizer(wxHORIZONTAL);
    sizer_3->Add(label_name, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_3->Add(text_ctrl_name, 1, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_2->Add(sizer_3, 0, wxALL|wxEXPAND, 3);
    sizer_4->Add(label_x, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4->Add(text_ctrl_x, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4->Add(label_y, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4->Add(text_ctrl_y, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4->Add(label_z, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4->Add(text_ctrl_z, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4->Add(combo_box_pos_unit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_2->Add(sizer_4, 0, wxALL|wxEXPAND, 3);
    sizer_4_copy->Add(label_roll, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy->Add(text_ctrl_roll, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy->Add(label_pitch, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy->Add(text_ctrl_pitch, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy->Add(label_yaw, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy->Add(text_ctrl_yaw, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy->Add(combo_box_orient_unit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_2->Add(sizer_4_copy, 0, wxALL|wxEXPAND, 3);
    sizer_1->Add(sizer_2, 0, wxALL|wxEXPAND, 3);
    sizer_5->Add(text_ctrl_feed, 1, wxALL|wxEXPAND, 3);
    sizer_1->Add(sizer_5, 0, wxALL|wxEXPAND, 3);
    sizer_3_copy->Add(label_name_copy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_3_copy->Add(text_ctrl_name_copy, 1, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_2_copy->Add(sizer_3_copy, 0, wxALL|wxEXPAND, 3);
    sizer_4_copy_1->Add(label_x_copy_1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_1->Add(text_ctrl_x_copy_1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_1->Add(label_y_copy_1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_1->Add(text_ctrl_y_copy_1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_1->Add(label_z_copy_1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_1->Add(text_ctrl_z_copy_1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_1->Add(combo_box_pos_unit_copy_1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_2_copy->Add(sizer_4_copy_1, 0, wxALL|wxEXPAND, 3);
    sizer_4_copy_copy->Add(label_roll_copy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_copy->Add(text_ctrl_roll_copy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_copy->Add(label_pitch_copy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_copy->Add(text_ctrl_pitch_copy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_copy->Add(label_yaw_copy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_copy->Add(text_ctrl_yaw_copy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_copy->Add(combo_box_orient_unit_copy, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_2_copy->Add(sizer_4_copy_copy, 0, wxALL|wxEXPAND, 3);
    sizer_1->Add(sizer_2_copy, 0, wxALL|wxEXPAND, 3);
    sizer_6->Add(button_ok, 1, wxALL, 10);
    sizer_6->Add(button_cancel, 1, wxALL, 10);
    sizer_1->Add(sizer_6, 1, wxEXPAND, 0);
    SetAutoLayout(true);
    SetSizer(sizer_1);
    sizer_1->Fit(this);
    sizer_1->SetSizeHints(this);
    Layout();
    // end wxGlade
}

void EngineThrusterDialog::Load(const ClientData_engine * data)
{
  file_e = data->file_e;
  file_t = data->file_t;
  loc_e  = data->loc_e;
  ori_e  = data->ori_e; 
  loc_t  = data->loc_t; 
  ori_t  = data->ori_t;

  feed.Empty();
  for (size_t i = 0u; i < data->feed_list.size(); ++i)
  {
    feed += wxString::Format(wxT("%d "), data->feed_list[i]);
  }
}

void EngineThrusterDialog::Save(ClientData_engine * data)
{
  data->file_e = file_e;
  data->file_t = file_t;
  data->loc_e  = loc_e;
  data->ori_e  = ori_e; 
  data->loc_t  = loc_t; 
  data->ori_t  = ori_t;

  data->feed_list.clear();
  
  size_t len = feed.Length();
  size_t i=0u, j=0u;
  while (i<len)
  {
    while ((feed[i]<'0'||feed[i]>'9')&&i<len) ++i;
    if (i>=len)
      break;
    j = i;
    while (feed[j]>='0'&&feed[j]<='9'&&j<len) ++j;
    unsigned long tmp;
    feed.Mid(i,j-i).ToULong(&tmp);
    data->feed_list.push_back((unsigned)tmp);
    i = j;
  }

}

/****************************************************************************
void EngineThrusterDialog::OnEngineDetail(wxCommandEvent& event)
{
  wxString sac = text_ctrl_name->GetValue();
  wxString ca = wxGetApp().engine_dir + wxGetApp().Delimited + sac + wxT(".xml");
  if ( ::wxFileExists(ca))
  {
    TurbineDialog dlg(this, -1, wxT("Engine Commander"));
    if (!dlg.Load(ca))
    {
      ::wxMessageBox(wxT("Something is wrong! I can not load proper file(") + ca + wxT(")."), wxT("Warning"), wxOK | wxICON_INFORMATION, this);
    }
    else if (dlg.ShowModal() == wxID_OK)
    {
      if (!dlg.Save())
      {
        ::wxMessageBox(wxT("Something is wrong! I can not save proper file(") + ca + wxT("). Please check it."), wxT("Error"), wxOK | wxICON_ERROR, this);
      }
    }
  }
  else
  {
      ::wxMessageBox(wxT("Something is wrong! I can not find proper file(") + ca + wxT("). Please check it."), wxT("Error"), wxOK | wxICON_ERROR, this);  
  }
  
}

void EngineThrusterDialog::OnEngineSelect(wxCommandEvent &event)
{
  wxString sac = text_ctrl_name->GetValue();
  wxString ca = wxGetApp().engine_dir + wxGetApp().Delimited + sac + wxT(".xml");
  {
    EngineMgrDialog dlg(sac, this, -1, wxT("Resets Manager"));
    dlg.ShowModal();
    text_ctrl_name->SetValue(dlg.GetResult());
  }
}
****************************************************************************/

TankDialog::TankDialog(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
    wxDialog(parent, id, title, pos, size, style)
{
    // begin wxGlade: TankDialog::TankDialog
    sizer_4_copy_2_staticbox = new wxStaticBox(this, -1, _("Location"));
    label_type = new wxStaticText(this, -1, _("Type:"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    const wxString combo_box_type_choices[] = {
        wxT("FUEL"),
        wxT("OXIDIZER")
    };
    combo_box_type = new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_type_choices, wxCB_DROPDOWN|wxCB_READONLY, wxGenericValidator(&type) );
    label_capacity = new wxStaticText(this, -1, _("capacity ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_capacity = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &capacity) );
    const wxString combo_box_capacity_choices[] = {
        wxT("LBS"),
        wxT("KG")
    };
    combo_box_capacity = new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_capacity_choices, wxCB_DROPDOWN|wxCB_READONLY, wxGenericValidator(&capacity_unit) );
    label_contents = new wxStaticText(this, -1, _("contents ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_contents = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &contents) );
    const wxString combo_box_contents_choices[] = {
        wxT("LBS"),
        wxT("KG")
    };
    combo_box_contents = new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_contents_choices, wxCB_DROPDOWN|wxCB_READONLY, wxGenericValidator(&contents_unit) );
    label_x_copy_2 = new wxStaticText(this, -1, _("x ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_x = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(loc.x1)) );
    label_y_copy_2 = new wxStaticText(this, -1, _("y ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_y = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(loc.x2)) );
    label_z_copy_2 = new wxStaticText(this, -1, _("z ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_z = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC, &(loc.x3)) );
    const wxString combo_box_pos_unit_choices[] = {
        wxT("IN"),
        wxT("FT"),
        wxT("M")
    };
    combo_box_pos_unit = new wxComboBox(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 3, combo_box_pos_unit_choices, wxCB_DROPDOWN|wxCB_READONLY, wxGenericValidator(&(loc.unit)));
    button_ok_copy = new wxButton(this, wxID_OK, _("OK"));
    button_cancel_copy = new wxButton(this, wxID_CANCEL, _("Cancel"));

    set_properties();
    do_layout();
    // end wxGlade
}


void TankDialog::set_properties()
{
    // begin wxGlade: TankDialog::set_properties
    label_type->SetMinSize(wxSize(80, 20));
    combo_box_type->SetSelection(0);
    label_capacity->SetMinSize(wxSize(80, 20));
    combo_box_capacity->SetSelection(0);
    label_contents->SetMinSize(wxSize(80, 20));
    combo_box_contents->SetSelection(0);
    label_x_copy_2->SetMinSize(wxSize(45, 20));
    label_y_copy_2->SetMinSize(wxSize(40, 20));
    label_z_copy_2->SetMinSize(wxSize(40, 20));
    combo_box_pos_unit->SetSelection(0);
    // end wxGlade
}


void TankDialog::do_layout()
{
    // begin wxGlade: TankDialog::do_layout
    wxBoxSizer* sizer_7 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_6_copy = new wxBoxSizer(wxHORIZONTAL);
    wxStaticBoxSizer* sizer_4_copy_2 = new wxStaticBoxSizer(sizer_4_copy_2_staticbox, wxHORIZONTAL);
    wxBoxSizer* sizer_9 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_8 = new wxBoxSizer(wxHORIZONTAL);
    sizer_8->Add(label_type, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_8->Add(combo_box_type, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_7->Add(sizer_8, 1, wxEXPAND, 0);
    sizer_9->Add(label_capacity, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_9->Add(text_ctrl_capacity, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_9->Add(combo_box_capacity, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_9->Add(label_contents, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_9->Add(text_ctrl_contents, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_9->Add(combo_box_contents, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_7->Add(sizer_9, 1, wxEXPAND, 0);
    sizer_4_copy_2->Add(label_x_copy_2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_2->Add(text_ctrl_x, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_2->Add(label_y_copy_2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_2->Add(text_ctrl_y, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_2->Add(label_z_copy_2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_2->Add(text_ctrl_z, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_4_copy_2->Add(combo_box_pos_unit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 3);
    sizer_7->Add(sizer_4_copy_2, 0, wxALL|wxEXPAND, 3);
    sizer_6_copy->Add(button_ok_copy, 1, wxALL, 10);
    sizer_6_copy->Add(button_cancel_copy, 1, wxALL, 10);
    sizer_7->Add(sizer_6_copy, 0, wxEXPAND, 0);
    SetAutoLayout(true);
    SetSizer(sizer_7);
    sizer_7->Fit(this);
    sizer_7->SetSizeHints(this);
    Layout();
    // end wxGlade
}


void TankDialog::Load(const ClientData_tank * data)
{
    type = data->type;
    capacity = wxString::Format(wxT("%g"), data->capacity);
    capacity_unit = data->capacity_unit;
    contents = wxString::Format(wxT("%g"), data->contents);
    contents_unit = data->contents_unit;
    loc = data->loc;
}

void TankDialog::Save(ClientData_tank * data)
{
    double tmp;
    data->type = type;
    if (capacity.ToDouble(&tmp))
      data->capacity = tmp;
    data->capacity_unit = capacity_unit;
    if (contents.ToDouble(&tmp))
      data->contents = tmp;
    data->contents_unit = contents_unit;
    data->loc = loc;
}

